<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>About Function | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="let’s talk some vital details of FinctionFunction pre-resolution (函数预解析早知道)123456789console.log(typeof fn)//第一个console.log 打印出的值是function 说明函数在预解析阶段 若出现同名函数和变量，以函数为准 function fn() &amp;#123;    console.lo">
<meta property="og:type" content="article">
<meta property="og:title" content="About Function">
<meta property="og:url" content="http://xgx-wanderer.oschina.io/2017/08/25/About Function(关于函数)/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="let’s talk some vital details of FinctionFunction pre-resolution (函数预解析早知道)123456789console.log(typeof fn)//第一个console.log 打印出的值是function 说明函数在预解析阶段 若出现同名函数和变量，以函数为准 function fn() &amp;#123;    console.lo">
<meta property="og:updated_time" content="2017-09-09T02:24:59.120Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="About Function">
<meta name="twitter:description" content="let’s talk some vital details of FinctionFunction pre-resolution (函数预解析早知道)123456789console.log(typeof fn)//第一个console.log 打印出的值是function 说明函数在预解析阶段 若出现同名函数和变量，以函数为准 function fn() &amp;#123;    console.lo">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="Flux RSS"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Rechercher"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://xgx-wanderer.oschina.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-About Function(关于函数)" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2017/08/25/About Function(关于函数)/" class="article-date">
  <time datetime="2017-08-25T12:56:10.278Z" itemprop="datePublished">2017-08-25</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      About Function
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="let’s-talk-some-vital-details-of-Finction"><a href="#let’s-talk-some-vital-details-of-Finction" class="headerlink" title="let’s talk some vital details of Finction"></a>let’s talk some vital details of Finction</h2><h3 id="Function-pre-resolution-函数预解析早知道"><a href="#Function-pre-resolution-函数预解析早知道" class="headerlink" title="Function pre-resolution (函数预解析早知道)"></a>Function pre-resolution (函数预解析早知道)</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> fn)</div><div class="line"><span class="comment">//第一个console.log 打印出的值是function 说明函数在预解析阶段 若出现同名函数和变量，以函数为准</span></div><div class="line"> </div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">'hello world'</span>)</div><div class="line">&#125;</div><div class="line">   <span class="keyword">var</span> fn=<span class="number">123</span></div><div class="line"></div><div class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> fn)<span class="comment">//第二个console.log打印输出的是number 说明虽然函数在预解析阶段先于变量，但是在执行阶段，函数没有被调用，所以被pass掉了，fn被重新赋值为123，所以打印输出了number类型</span></div></pre></td></tr></table></figure>
<h3 id="Function-declaration-and-expression-函数声明与函数表达式"><a href="#Function-declaration-and-expression-函数声明与函数表达式" class="headerlink" title="Function declaration and expression(函数声明与函数表达式)"></a>Function declaration and expression(函数声明与函数表达式)</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//1.函数声明必须要有名字,函数声明会函数提升，声明前后都可以被调用</span></div><div class="line">    <span class="comment">//2.函数表达式类似于变量赋值，可以没有名字，不会函数提升，执行时，必须在表达式执行之后才可以调用</span></div><div class="line">     <span class="keyword">var</span> condition=<span class="literal">true</span>;</div><div class="line">     <span class="keyword">if</span>(<span class="literal">true</span>)&#123;</div><div class="line">       <span class="function"><span class="keyword">function</span> <span class="title">f1</span>(<span class="params"></span>) </span>&#123;</div><div class="line">           <span class="built_in">console</span>.log(<span class="number">1111</span>)</div><div class="line">       &#125;</div><div class="line">     &#125;<span class="keyword">else</span>&#123;</div><div class="line">       <span class="function"><span class="keyword">function</span> <span class="title">f2</span>(<span class="params"></span>) </span>&#123;</div><div class="line">         <span class="built_in">console</span>.log(<span class="number">2222</span>)</div><div class="line">       &#125;</div><div class="line">     &#125;<span class="comment">//以上代码执行结果在不同浏览器中结果不一致。(在 JavaScript 中，没有块作用域,一些老的浏览器会先进行函数提升)</span></div><div class="line">     <span class="comment">//这种情况就可以用  函数表达式解决，因为函数表达式没有函数提升</span></div><div class="line">     <span class="keyword">var</span> fn;</div><div class="line">     <span class="keyword">if</span>(<span class="literal">true</span>)&#123;</div><div class="line">      fn= <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</div><div class="line">         <span class="built_in">console</span>.log(<span class="number">3333</span>)</div><div class="line">       &#125;</div><div class="line">     &#125;<span class="keyword">else</span>&#123;</div><div class="line">       fn=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</div><div class="line">         <span class="built_in">console</span>.log(<span class="number">4444</span>)</div><div class="line">       &#125;</div><div class="line">     &#125;</div></pre></td></tr></table></figure>
<h3 id="THIS-THIS-THIS-函数内this指向问题"><a href="#THIS-THIS-THIS-函数内this指向问题" class="headerlink" title="THIS! THIS! THIS!(函数内this指向问题)"></a>THIS! THIS! THIS!(函数内this指向问题)</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//this 非常难哦 这里大家要好好学习哟！</span></div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://xgx-wanderer.oschina.io/2017/08/25/About Function(关于函数)/" data-id="cj7cp46yh0001d0r3qj8ebw44" class="article-share-link">Partager</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/09/08/About Markdown/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Récent</strong>
      <div class="article-nav-title">
        
          About Markdown
        
      </div>
    </a>
  
  
    <a href="/2017/08/25/first blog/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Ancien</strong>
      <div class="article-nav-title">My first personal blog!</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">September 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">August 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Articles récents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/09/10/字体图标/">字体图标的那些事</a>
          </li>
        
          <li>
            <a href="/2017/09/08/About Markdown/">About Markdown</a>
          </li>
        
          <li>
            <a href="/2017/08/25/About Function(关于函数)/">About Function</a>
          </li>
        
          <li>
            <a href="/2017/08/25/first blog/">My first personal blog!</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 codeDog-xgx<br>
      Propulsé by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>